<?php

namespace App\Admin\Controllers;

use App\Models\ExperienceModel;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class ExperienceController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '心得游记';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new ExperienceModel());

        $grid->column('id', __('Id'));
        $grid->column('title','标题');
        $grid->column('country','国家');
        //$grid->column('line_id', __('Line id'));
        $grid->column('line','线路');
        //$grid->column('city', __('City'));
        //$grid->column('country_id', __('Country id'));
        //$grid->column('city_id', __('City id'));
        $grid->column('user_name','用户名');
        //$grid->column('user_id', __('User id'));
        $grid->column('itinerary_date','行程日期');
        //$grid->column('route_line','行程线路');
        //$grid->column('html', __('Html'));
        $grid->column('head_img','头像');
        $grid->column('created_at', __('Created at'));
        $grid->column('updated_at', __('Updated at'));
        $grid->disableCreateButton();
        $grid->disableFilter();
        $grid->disableExport();

        $grid->actions(function ($actions) {
           // $actions->disableDelete();
            $actions->disableEdit();
        });

        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(ExperienceModel::findOrFail($id));

        $show->field('id', __('Id'));
        $show->field('title','标题');
        $show->field('country','国家');
        //$show->field('line_id', __('Line id'));
        $show->field('line','线路类型');
        //$show->field('city', __('City'));
        //$show->field('country_id', __('Country id'));
        //$show->field('city_id', __('City id'));
        $show->field('user_name','用户名');
       // $show->field('user_id', __('User id'));
        $show->field('itinerary_date','行程日期');
       // $show->field('route_line', __('Route line'));
        $show->route_line('行程线路') -> unescape()->as(function ($route_line) {
            $string='';
            // 获取该服务项目下的问题
            foreach ($route_line as $v){
                //var_dump($v['title']);die;
                $string.="<pre>时间:{$v['time']}<br/>内容:{$v['content']}<br/>线路:{$v['line']}</pre>";
            }
            return $string;
        });
        //$show->extra('route_line')->json();
        $show->field('html','图文详情');
        $show->field('head_img','头像');
        $show->field('created_at', __('Created at'));
        $show->field('updated_at', __('Updated at'));

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
    /*    $form = new Form(new ExperienceModel());

        $form->text('title', __('Title'));
        $form->text('country', __('Country'));
        $form->number('line_id', __('Line id'));
        $form->text('line', __('Line'));
        $form->text('city', __('City'));
        $form->number('country_id', __('Country id'));
        $form->number('city_id', __('City id'));
        $form->text('user_name', __('User name'));
        $form->number('user_id', __('User id'));
        $form->text('itinerary_date', __('Itinerary date'));
        $form->textarea('route_line', __('Route line'));
        $form->textarea('html', __('Html'));
        $form->text('head_img', __('Head img'));

        return $form;*/
    }
}
